<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
<script type="text/javascript">
var rulemanager={
	filepath:"",
	basepath:"",
	uploade:function(d){
		var record = Ext.getCmp("f_grid").getSelectionModel().getSelected();
		if(record){
			if(d.indexOf("success")==0){
			
			    var i = F_store.f_store.find("front",d.substr(6),0,true,true);//匹配store中的路径,已有不再新增
				if(i==-1){
					Ext.Ajax.request({
						url: "paper!updPaperInfo.action",
						params: {
							"paperInfo.id": record.data.id,
							"paperInfo.bg_no": record.data.bg_no,
							"paperInfo.front":d.substr(7)
						},
						success: function(res){
							F_store.f_store.load({params:{"paperCC.paper_no": record.data.id}});
						}
					});
				}
				//Ext.Msg.alert("提示","上传成功！");
				Ext.Msg.show({
		   			title:"提示",
		   			msg:"操作成功!",
		   			buttons:Ext.Msg.OK,
		   			icon: Ext.MessageBox.INFO
					});
			}
			else if(d.indexOf("exists")==0){
				//Ext.Msg.alert("提示","文件已存在,请重新选择上传的文件");
				Ext.Msg.show({
		   			title:"提示",
		   			msg:"文件已存在,请重新选择上传的文件!",
		   			buttons:Ext.Msg.OK,
		   			icon: Ext.MessageBox.ERROR
					});
			}
		}
	}
};
//预印纸从表数据源
var F_store = {
	f_store : new Ext.data.JsonStore({
		root: "data",
		idProperty: "bg_no",
		fields: ["id", "bg_no", "bg_name", "befor_type","front"],
		url: "paper!paperInfoList.action"
	})
};


	var prod_opera;//传给ajax url属性的action字符串
	var opt=false;//增加规则按钮操作标示
	
	/*********************************************************************/
	//预印纸数据源
	var store = new Ext.data.JsonStore({
		root: "data",
	   	totalProperty: "total",
	   	fields : [ "pid","paper_no","paper_name","paper_weight",
	   	   	"person_no","create_time","period_begin","period_end","period_day","businpnt_name","businpnt_no"],
		url : "paper!GridList.action"
	});

	//卡产品关联的外包商数据源
	var b_store = new Ext.data.JsonStore({
		root: "data",
       	totalProperty: "total",
		fields: ["id", "name", "linkman", "linkphone","linkaddr", "state",
				"ftp", "port", "ftpuser", "ftppass", "ftppath", "remark"],
       	url: "epiboly!condiList.action"
	});
	/*********************************************************************/
	
	var p1 = {
		id : "p1",
		xtype: "grid",
		stripeRows:true,
		loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
		autoExpandColumn:"paper_name",//自动填充
		autoExpandMin : 100,//自动填充最小宽度
		store : store,
		headersDisabled: true,
		columns : [  new Ext.grid.RowNumberer({header: "序号", width: 35}),
		            {dataIndex : "pid",			header : "序列号",	menuDisabled: true},
		            {dataIndex : "paper_no",	header : "预印纸编号",	menuDisabled: true},
		            {dataIndex : "businpnt_name",	header : "外包商",	menuDisabled: true},
		            {dataIndex : "paper_name",	header : "名称",id:"paper_name",menuDisabled: true},      
		            {dataIndex : "paper_weight",header : "克重",		menuDisabled: true},
		            {dataIndex : "period_begin",header : "有效开始月",	menuDisabled: true},
		            {dataIndex : "period_end",	header : "有效截止月",	menuDisabled: true},
		            {dataIndex : "period_day",	header : "账单日",	menuDisabled: true},
		            {dataIndex : "person_no",	header : "创建人",	menuDisabled: true},
		            {dataIndex : "create_time",	header : "创建时间",	menuDisabled: true}
		],
		bbar: new Ext.ux.PagingToolbar( {
			pageSize : limit,
			store : store
		}),
		buttonAlign : "center",
		buttons : [
				{
					text : "查看详情",
					handler : function() {
						prod_opera = "paper!updPaper.action";
						var record = Ext.getCmp("p1").getSelectionModel().getSelected();
						var node=Ext.getCmp("prod_tree").getSelectionModel().getSelectedNode();//当前选中的树节点
						if (record) {
								Ext.getCmp("rule_panel").layout.setActiveItem(1);
								Ext.getCmp("areaform").setParam(record.data);
								Ext.Ajax.request({
									url: "treeCheck!cardCity1.action",
									params: {
										"paperCityCrd.card_no": Ext.getCmp("prod_tree").getSelectionModel().getSelectedNode().id,
										"paperCityCrd.paper_no": Ext.getCmp("pid").getValue(),
										"paperCityCrd.businpnt_no": Ext.getCmp("businpnt_no").getValue()
									},
									success: function(res){
										var rootnode = Ext.getCmp("rolefuncpanel").getRootNode();
										rootnode.removeAll();
										rootnode.appendChild(eval("("+res.responseText+")"));
									}
								});
								//加载从表数据
								F_store.f_store.load({params:{"paperCC.paper_no": record.data.pid}});
						} else {
							//Ext.Msg.alert("警告","请先选择一条记录，然后点击修改!");
							Ext.Msg.show({
		   						title:"警告",
		   						msg: "未选中任何行信息,无法进行此操作!",
		   						buttons: Ext.Msg.OK,
		   						animEl: "elId",
		   						icon:Ext.MessageBox.WARNING
								});
						}
					}
				}]
	};

	var org_add_update = 0;
    
	var p2 = {
		id:"areaform",
		region: "north",
		height:250,
		columnWidth: 1,
		xtype :"form",
		title:"预印纸信息",
		bodyStyle : "padding:5px 5px 0",
		defaultType : "textfield",
		items : [
		{	id: "pid",
			fieldLabel : "序列号",
			anchor:"100%",
			disabled: true
		},{	id:"paper_no",
			fieldLabel : "预印纸编号",
			maxLength:30,
			anchor:"100%",
			disabled: true
		},{	id: "paper_name",
			fieldLabel : "预印纸名称",
			vtype:"alphanumchinese",
			disabled: true,
			anchor:"100%"
		},{	id:"businpnt_no",
			fieldLabel:"外包商",
			name :"businpnt_no",
			xtype:"billCombox",
			store: b_store,
			valueField: "id",
			disabled: true,
			displayField: "name"
		},{	id: "paper_weight",
			fieldLabel: "克重",
			xtype:"numberfield",
			anchor: "100%",			
			disabled: true
		},{
			id : "period_begin",
			fieldLabel : "有效开始月",
			anchor:"100%",
			vtype: "daterange",
       		endDateField: "period_end",
			xtype:"datefield",format:"Y-m",
			disabled: true
		},{
			id : "period_end",
			fieldLabel : "账期截止月",
			anchor:"100%",
			vtype: "daterange",
       		startDateField: "period_begin",
			xtype:"datefield",format:"Y-m",			
			disabled: true
		},{
			id : "period_day",
			fieldLabel : "账单日",
			anchor:"100%",
			xtype:"datefield",format:"d",
			disabled: true
		}],
		setParam : function(data) {
			Ext.getCmp("pid").setValue(data.pid);
			Ext.getCmp("paper_no").setValue(data.paper_no);
			Ext.getCmp("businpnt_no").setValue(data.businpnt_no);
			Ext.getCmp("paper_name").setValue(data.paper_name);
			Ext.getCmp("paper_weight").setValue(data.paper_weight);
			Ext.getCmp("period_begin").setValue(data.period_begin);
			Ext.getCmp("period_end").setValue(data.period_end);
			Ext.getCmp("period_day").setValue(data.period_day);
		}
	};
	
	var personrule = new Ext.grid.GridPanel({
        store: F_store.f_store,
        id:"f_grid",
        title: "底板信息",
        stripeRows : true,
        selModel : new Ext.grid.RowSelectionModel(),//设置为行选择器
        region: "center",
        columns:[
        	{header: "底板编号",	dataIndex:"bg_no"},
			{header: "底板名称",	dataIndex:"bg_name"},
			{header: "类型", 	dataIndex:"befor_type"
				,renderer:function(value){
					if(value == 1) return "正";
					else if(value == 2) return "反";
				}},
			{header: "上传状态",	dataIndex:"front"	
				,renderer:function(value){
					if(null != value) return "已上传";
					else return "待上传";
				}
			},
			{	xtype:"actioncolumn",
    			header: "预览",
    			width:34,
    			items:[{
			    icon:"images/shared/icons/fam/information.png",  // Use a URL in the icon config
                tooltip:"预览",
                handler: function(grid, rowIndex, colIndex) {
					var rec = F_store.f_store.getAt(rowIndex);
					var win=Ext.getCmp("showimages");
					win.show();
					var html="<img id='imgpage' width="+win.getInnerWidth()+" height="+win.getInnerHeight()+" src='download.action?id="+encodeURI(rec.get('front'))+"' />";
					win.update(html);
					return false;
                 }
             }]
			}
		],
		listeners:{
			"click":function(){
				var record = personrule.getSelectionModel().getSelected();
				if(record){
					rulemanager.filepath=rulemanager.basepath+record.data.bg_name+".jpg";
					getFlashObject("flashupload").addID(rulemanager.filepath);
				}
		}}
    });

    var rulePanel2 = {
    	xtype:"billTreePanel",
	    id:"rolefuncpanel",
	    region: "east",
	    split:false,
       	width:200,
    	border:true,
		autoScroll:true,
		title:"城市预印纸设置",
		rootVisible:false,
		root:{
			id:"root"
		}
    };
   
	var p3=new Ext.Panel({
		id:"view3",
		layout:"border",
		border:false,
		autoScroll: true,
		items:[p2,{
			region: "center",
			xtype: "panel",
			id:"rulePanl",
			layout:"border",
			border:false,
			items: [personrule,rulePanel2]
		}],
		buttonAlign : "center",
		buttons : [{
			text : "返回",
			handler : function(){
				Ext.getCmp("rule_panel").layout.setActiveItem(0);
			}
		}]
	});

	//获取文件上传路径
	var query = function(node){
		if(node.parentNode.id == "root") {
			return 	node.id;
		} else if(node.isLeaf()) {
			return query(node.parentNode)+"/PREVIEW/"+node.id+"/";
		}
		return query(node.parentNode);
	};
	
	var paper_pel = new Ext.Panel( {
		border : false, 
		layout : "border",
		items:[{
			id:"prod_tree",
			xtype : "billTreePanel",
			dataUrl : "tree!product.action",
			root : new Ext.tree.AsyncTreeNode( {
				id : "root",
				expanded : true
			// 自动展开节点
			}),
			listeners : {
				"click"	: function(node) {
				    if(node.isLeaf()){
				    	store.baseParams = store.baseParams || {};
				    	store.baseParams["paperCC.card_no"] = node.id;
				    	store.load({params:{start : 0,limit : limit}});
						b_store.load({params:{"paperCC.card_no": node.id}});
						rulemanager.basepath=query(node);
						Ext.getCmp("rule_panel").layout.setActiveItem(0);
				    }
				}
			}
		}, {
			region: "center",
			id:"rule_panel",
			border : false, 
			layout:"card",
			activeItem:0,//显示第一个容器
			items: [p1, p3]
		} ]
	});
	
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(paper_pel);
	CenterPanel.doLayout();


</script>